package com.cvr.project.repertory;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider;

/**
 * _ooOoo_
 * o8888888o
 * 88" . "88
 * (| -_- |)
 * O\ = /O
 * ____/`---'\____
 * .   ' \\| |// `.
 * / \\||| : |||// \
 * / _||||| -:- |||||- \
 * | | \\\ - /// | |
 * | \_| ''\---/'' | |
 * \ .-\__ `-` ___/-. /
 * ___`. .' /--.--\ `. . __
 * ."" '< `.___\_<|>_/___.' >'"".
 * | | : `- \`.;`\ _ /`;.`/ - ` : | |
 * \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 * `=---='
 * .............................................
 * 佛祖保佑             永无BUG
 *
 * @author :created by master
 * time :2021-6-29 21:58:05
 * 描述：初始化LViewModelProviders
 */
public class LViewModelProviders {
    public static <T extends BaseViewModel> T of(FragmentActivity activity, Class<T> modelClass) {
        T t = new ViewModelProvider(activity,new ViewModelProvider.NewInstanceFactory()).get(modelClass);
        t.setLifecycleOwner(activity);
        return t;
    }

    public static <T extends BaseViewModel> T of(@NonNull Fragment fragment, Class<T> modelClass) {
        T t = new ViewModelProvider(fragment,new ViewModelProvider.NewInstanceFactory()).get(modelClass);
        t.setLifecycleOwner(fragment);
        return t;
    }
}
